package com.ruoyi.handing.service.impl;

import java.util.Date;
import java.util.List;

import com.ruoyi.handing.domain.AlgsReviewRecord;
import com.ruoyi.handing.mapper.AlgsReviewRecordMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.handing.mapper.AlgsEthicalReviewMapper;
import com.ruoyi.handing.domain.AlgsEthicalReview;
import com.ruoyi.handing.service.IAlgsEthicalReviewService;

import javax.annotation.Resource;

/**
 * 伦理审核Service业务层处理
 * 
 * @author ruoyi
 * @date 2023-03-17
 */
@Service
public class AlgsEthicalReviewServiceImpl implements IAlgsEthicalReviewService 
{
    @Autowired
    private AlgsEthicalReviewMapper algsEthicalReviewMapper;
    @Resource
    private AlgsReviewRecordMapper reviewRecordMapper;

    /**
     * 查询伦理审核
     * 
     * @param ethicalReviewId 伦理审核主键
     * @return 伦理审核
     */
    @Override
    public AlgsEthicalReview selectAlgsEthicalReviewByEthicalReviewId(Long ethicalReviewId)
    {
        return algsEthicalReviewMapper.selectAlgsEthicalReviewByEthicalReviewId(ethicalReviewId);
    }

    /**
     * 查询伦理审核列表
     * 
     * @param algsEthicalReview 伦理审核
     * @return 伦理审核
     */
    @Override
    public List<AlgsEthicalReview> selectAlgsEthicalReviewList(AlgsEthicalReview algsEthicalReview)
    {
        return algsEthicalReviewMapper.selectAlgsEthicalReviewList(algsEthicalReview);
    }

    /**
     * 新增伦理审核
     * 
     * @param algsEthicalReview 伦理审核
     * @return 结果
     */
    @Override
    public int insertAlgsEthicalReview(AlgsEthicalReview algsEthicalReview)
    {
        return algsEthicalReviewMapper.insertAlgsEthicalReview(algsEthicalReview);
    }

    /**
     * 修改伦理审核
     * 
     * @param algsEthicalReview 伦理审核
     * @return 结果
     */
    @Override
    public int updateAlgsEthicalReview(AlgsEthicalReview algsEthicalReview)
    {
        return algsEthicalReviewMapper.updateAlgsEthicalReview(algsEthicalReview);
    }

    /**
     * 批量删除伦理审核
     * 
     * @param ethicalReviewIds 需要删除的伦理审核主键
     * @return 结果
     */
    @Override
    public int deleteAlgsEthicalReviewByEthicalReviewIds(Long[] ethicalReviewIds)
    {
        return algsEthicalReviewMapper.deleteAlgsEthicalReviewByEthicalReviewIds(ethicalReviewIds);
    }

    /**
     * 删除伦理审核信息
     * 
     * @param ethicalReviewId 伦理审核主键
     * @return 结果
     */
    @Override
    public int deleteAlgsEthicalReviewByEthicalReviewId(Long ethicalReviewId)
    {
        return algsEthicalReviewMapper.deleteAlgsEthicalReviewByEthicalReviewId(ethicalReviewId);
    }

    @Override
    public int addE(Long ethicalReviewId) {
        AlgsEthicalReview algsEthicalReview = algsEthicalReviewMapper.selectAlgsEthicalReviewByEthicalReviewId(ethicalReviewId);
        AlgsReviewRecord algsReviewRecord = new AlgsReviewRecord();
        algsReviewRecord.setNewExperimentName(algsEthicalReview.getEthicalReviewBy2());
        algsReviewRecord.setEthicalReviewId(algsEthicalReview.getEthicalReviewId());
        algsEthicalReview.setEthicalReviewBy3("审核通过");
        Date date = new Date();
        algsEthicalReview.setEthicalReviewDate(date);
        algsEthicalReview.setEthicalReviewBy1("李大锤");
        algsEthicalReviewMapper.updateAlgsEthicalReview(algsEthicalReview);
        return reviewRecordMapper.insertAlgsReviewRecord(algsReviewRecord);
    }

    @Override
    public int noAddE(Long ethicalReviewId) {
        AlgsEthicalReview algsEthicalReview = algsEthicalReviewMapper.selectAlgsEthicalReviewByEthicalReviewId(ethicalReviewId);
//        System.out.println(algsEthicalReview);
        algsEthicalReview.setEthicalReviewBy3("审核不通过");
        return algsEthicalReviewMapper.updateAlgsEthicalReview(algsEthicalReview);
    }
}
